import React from 'react'

import { Route, Redirect } from 'react-router-dom'

import { isAuth } from '../../utils'

// <AuthRoute path="..." componeent={...}></AuthRoute>
const AuthRoute = ({ component: Component ,...rest}) => {
    return <Route {...rest} render={props=>{
        const isLogin = isAuth()
        if(isLogin){
            //将props传递给组件组件中才能获取路由的相关信息
            return <Component {...props}/>
        }else{
            return <Redirect to={{
                pathname: '/login',
                state: {
                    from: props.location
                }
            }}/>
        }
    }}></Route>
}

export default AuthRoute